package com.simons.common.utils.xml.xstream;

import java.io.IOException;

/**
 * xml构建指挥者
 * 
 * @Description:TODO
 * 
 * @author:JSM
 * 
 * @time:2018年3月30日 下午5:15:51
 */
public class XmlDirector {
	/**
	 * 具体生产xml文件方法
	 * 
	 * @param t
	 * @param builderClass 具体建造者的类
	 * @param targetPath 目标文件地址
	 * @throws IllegalAccessException
	 * @throws InstantiationException
	 * @throws IOException 
	 */
	public <T> void Construct(T t, String targetPath, Class<? extends XmlConcreteBuilder> xmlBuilderClass, XstreamTypeEnum xstreamTypeEnum)
			throws InstantiationException, IllegalAccessException, IOException {
		XmlBuilder xmlBuilder = xmlBuilderClass.newInstance();
		// 创建对应的xstream
		switch (xstreamTypeEnum) {
		case SIMPLE:
			xmlBuilder.buildSimpleXstream();
			break;
		case ATTR:
			xmlBuilder.buildAttrXstream();
			break;
		default:
			break;
		}
		xmlBuilder.createXmlStr(t);
		xmlBuilder.makeXmlFile(targetPath);
	}
	
//	public static void main(String[] args) throws InstantiationException, IllegalAccessException, IOException {
//		XmlDirector xmlDirector = new XmlDirector();
//		ErrorInfo errorInfo = new ErrorInfo("asdasd","asdasd");
//		xmlDirector.Construct(errorInfo, "D:/test.txt", TestXmlClass.class);
//	}
}
